package com.kinth.work.zggys;

import java.util.ArrayList;

import com.kinth.dbutil.ImplDAO;
/**
 * 
 * <p>Title: 慧聪网的数据库工具类</p>
 * <p>Description: 
 * 主要是查和增。主要和ImplDAO交互。
 * </p>
 * @author 23192
 * @2017年3月28日
 */
public class dbUtil
{

	public static boolean insertUrl(GongYingShang url, String tableName)
	{
		String[] params = {url.getUrl(),url.getIndustry()};
		ImplDAO implDAO = new ImplDAO();
		String sql = "insert into `"+tableName+"` (`url`,`industry`)values(?,?)";
		try
		{
			return implDAO.doExecute(sql, params);
		} catch (Exception e)
		{
			// TODO Auto-generated catch block
			System.out.println("重复插入");
			//e.printStackTrace();
			
		}
		//System.out.println("可以");
		return false;
	}

	
	public static ArrayList<GongYingShang> queryUrl(String tableName, int row,int numOnce)
	{
		ArrayList<GongYingShang> result = new ArrayList<GongYingShang> ();
		ArrayList<String[]> all = new ArrayList<String[]>();
		String sql ="select * from "+tableName+" limit "+row+","+numOnce;
		ImplDAO dao = new ImplDAO();
		try {
			all = dao.doQuery(sql, null);
			for(int i = 0; i < all.size(); i++)
			{
				String []sTemp = all.get(i);
				GongYingShang url = new GongYingShang();
				url.setUrl(sTemp[0]);
				url.setIndustry(sTemp[1]);
				result.add(url);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
	
	public static void main(String[] args)
	{
		
	}
}
